package com.duleme.servlet;

import com.duleme.common.EncodeUtils;
import com.duleme.common.JsonUtils;
import com.duleme.dao.ShopDao;
import com.duleme.entity.Shop;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/data/shop")
public class ShopInfoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        EncodeUtils.setEncoding(req,resp);
        String shopName=req.getParameter("shopName");
        ShopDao dao=new ShopDao();
        Shop shop=dao.findShopByName(shopName);
        if (shop!=null){
            resp.getWriter().print(JsonUtils.result2Json("1","shopInfo",JsonUtils.toJson(shop)));
        }else
            resp.getWriter().print(JsonUtils.result2Json("0"));
    }
}
